local zhishui = fk.CreateSkill {
  name = "lingling__zhishui",
}

Fk:loadTranslationTable {
  ["lingling__zhishui"] = "治水",
  [":lingling__zhishui"] = "当一名角色的判定牌生效前，你可以用一张牌替换之。摸牌阶段，若你没有黑色手牌，你可以多摸两张牌。",

  ["#lingling__zhishui-ask"] = "治水：你可以用一张牌替换 %dest 的 %arg 判定！",
  ["#lingling__zhishui-draw"] = "治水：你可以多摸两张牌！",
}

zhishui:addEffect(fk.AskForRetrial, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(zhishui.name) and not player:isNude()
  end,
  on_cost = function(self, event, target, player, data)
    local card = player.room:askToCards(player, {
      min_num = 1,
      max_num = 1,
      include_equip = true,
      skill_name = zhishui.name,
      cancelable = true,
      prompt = "#lingling__zhishui-ask::" .. target.id .. ":" .. data.reason
    })
    if #card ~= 0 then
      event:setCostData(self, { cards = card })
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local card = event:getCostData(self).cards[1]
    room:changeJudge {
      data = data,
      player = player,
      card = Fk:getCardById(card),
      skillName = zhishui.name,
      exchange = true
    }
  end,
})

zhishui:addEffect(fk.DrawNCards, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(zhishui.name) and player == target and
        not (player:isKongcheng() or table.find(player:getCardIds("h"), function(id)
          return Fk:getCardById(id).color == Card.Black
        end))
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askToSkillInvoke(player, {
      skill_name = zhishui.name,
      prompt = "#lingling__zhishui-draw",
    })
  end,
  on_use = function(self, event, target, player, data)
    data.n = data.n + 2
  end
})

return zhishui
